package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.hr.dto.AttendWhitelistAddDTO;
import org.jsola.hr.dto.AttendWhitelistUpdateDTO;
import org.jsola.hr.entity.AttendWhitelistDO;
import org.jsola.hr.query.AttendWhitelistQuery;
import org.jsola.hr.service.IAttendWhitelistService;
import org.jsola.hr.vo.AttendWhitelistVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class AttendWhitelistTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAttendWhitelistService attendWhitelistService;

    /**
     * 生成add测试数据
     * @return AttendWhitelistAddDTO
     */
    public AttendWhitelistAddDTO getAttendWhitelistAddDTO(){
        AttendWhitelistAddDTO attendWhitelistAddDTO = new AttendWhitelistAddDTO();
        attendWhitelistAddDTO.setCompanyId(getRandomValue("varchar",32));
        attendWhitelistAddDTO.setCompanyName(getRandomValue("varchar",100));
        attendWhitelistAddDTO.setDeptId(getRandomValue("varchar",32));
        attendWhitelistAddDTO.setDeptName(getRandomValue("varchar",50));
        attendWhitelistAddDTO.setEmpInfoId(getRandomValue("varchar",32));
        attendWhitelistAddDTO.setEmpInfoName(getRandomValue("varchar",50));
        attendWhitelistAddDTO.setAttendPlanId(getRandomValue("varchar",32));
        return attendWhitelistAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AttendWhitelistUpdateDTO
     */
    public AttendWhitelistUpdateDTO getAttendWhitelistUpdateDTO(AttendWhitelistVO attendWhitelistVO){
        return attendWhitelistService.selectDOById(attendWhitelistVO.getId(), SITE_ID).to(AttendWhitelistUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AttendWhitelistQuery
     */
    public AttendWhitelistQuery getAttendWhitelistQuery() {
        AttendWhitelistQuery attendWhitelistQuery = new AttendWhitelistQuery();
        List<AttendWhitelistDO> attendWhitelistDOList = attendWhitelistService.list(new AttendWhitelistDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(attendWhitelistDOList)) {
            AttendWhitelistDO attendWhitelistDO = attendWhitelistDOList.get(0);
            attendWhitelistQuery = attendWhitelistDO.to(AttendWhitelistQuery.class);
            if (attendWhitelistDO.getGmtCreate() != null) {
                attendWhitelistQuery.setGmtCreateStart(DateKit.getBeforeDay(attendWhitelistDO.getGmtCreate(),-1));
                attendWhitelistQuery.setGmtCreateEnd(DateKit.getBeforeDay(attendWhitelistDO.getGmtCreate(),1));
            }
            if (attendWhitelistDO.getGmtModified() != null) {
                attendWhitelistQuery.setGmtModifiedStart(DateKit.getBeforeDay(attendWhitelistDO.getGmtModified(),-1));
                attendWhitelistQuery.setGmtModifiedEnd(DateKit.getBeforeDay(attendWhitelistDO.getGmtModified(),1));
            }
        }
        return attendWhitelistQuery;
    }

    /**
     * 保存示例
     * @return AttendWhitelistVO
     */
    public AttendWhitelistVO saveAttendWhitelistExample(){
        AttendWhitelistAddDTO addDTO = this.getAttendWhitelistAddDTO();
        AttendWhitelistVO attendWhitelistVO = attendWhitelistService.save(addDTO,buildTokenUser());
        return attendWhitelistVO;
    }


}

